-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add openai responses api capability #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@matthewmichel is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
New and updated dependencies detected. Learn more about Socket for GitHub ↗︎
|
the timeline of this pr is the reason why open source is the future. |
Sort and sweet. Love it! |
WalkthroughThe changes update the integration with the OpenAI SDK and related dependencies. The chat API handler now conditionally adds a Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ChatAPI (POST handler)
participant OpenAI
participant WebSearchPreview
Client->>ChatAPI (POST handler): Send chat request
ChatAPI (POST handler)->>OpenAI: Initialize with providerOptions (store: false)
alt Model is not "chat-model-reasoning"
ChatAPI (POST handler)->>WebSearchPreview: Add tool (searchContextSize: medium)
end
ChatAPI (POST handler)->>OpenAI: Send chat request with/without tool
OpenAI-->>ChatAPI (POST handler): Return response
ChatAPI (POST handler)-->>Client: Return chat response
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@tobiasbueschel Changes made to not store messages on the OpenAI side. Open to any other suggestions/feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @arvi18, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request focuses on updating the ai
and @ai-sdk/openai
packages to support the new OpenAI Responses API. It also updates the default "small" and "large" models to utilize this new API. Additionally, a webSearchPreview
tool call is added to demonstrate the OpenAI Web Search Preview tool.
Highlights
- OpenAI Responses API Support: The
ai
and@ai-sdk/openai
packages are updated to support the new OpenAI Responses API. - Model Updates: The default 'small' and 'large' models are updated to use the Responses API.
- Web Search Preview Tool: A new
webSearchPreview
tool call is added to showcase the OpenAI Web Search Preview tool.
Changelog
Click here to see the changelog
- app/(chat)/api/chat/route.ts
- Imported the
openai
module from@ai-sdk/openai
(line 28). - Added
webSearchPreview
to the list of allowed tool calls (line 89). - Implemented the
webSearchPreview
tool usingopenai.tools.webSearchPreview
with a 'medium' search context size (lines 101-103). - Added
providerOptions
to disable storing data for OpenAI (lines 105-107). - Corrected a typo in the error message from 'occured' to 'occurred' (line 147).
- Imported the
- lib/ai/providers.ts
- Updated the
chat-model-small
andchat-model-large
language models to useopenai.responses
instead ofopenai
(lines 28-29).
- Updated the
- package.json
- Updated the version of
@ai-sdk/openai
from 1.2.0 to 1.2.2 (line 23). - Updated the version of
ai
from 4.1.50 to 4.1.54 (line 43).
- Updated the version of
- pnpm-lock.yaml
- Updated the version of
@ai-sdk/openai
from 1.2.0 to 1.2.2 (line 15). - Updated the version of
ai
from 4.1.50 to 4.1.54 (line 75). - Updated the integrity hash for
@ai-sdk/openai
to the new version (line 273). - Added
@ai-sdk/[email protected]
and@ai-sdk/[email protected]
as dependencies (lines 288-299). - Added
@ai-sdk/[email protected]
as a dependency (lines 317-327). - Added
@ai-sdk/[email protected]
as a dependency (lines 338-346). - Updated the integrity hash for
ai
to the new version (line 1688). - Updated dependencies and integrity hashes for
@ai-sdk/openai
,@ai-sdk/provider-utils
,@ai-sdk/react
,@ai-sdk/ui-utils
, andai
in the snapshots section (lines 3850-5029).
- Updated the version of
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
The models now respond,
With answers from beyond,
Web search in the mix,
New features to fix,
AI's power unbound.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces the OpenAI Responses API, updates default models, and adds a web search preview tool. The changes seem well-structured and aligned with the feature's objective. However, there are a few areas that could benefit from closer attention.
Summary of Findings
- Error message typo: There's a typo in the error message within
app/(chat)/api/chat/route.ts
. It should be 'occurred' instead of 'occured'. - Tool call naming consistency: Consider whether
webSearchPreview
is the most descriptive and consistent name for the new tool call, and whether it aligns with existing naming conventions. - Dependency updates: The
package.json
andpnpm-lock.yaml
files have been updated with new versions ofai
and@ai-sdk/openai
. Ensure that these updates have been thoroughly tested and are compatible with the existing codebase.
Merge Readiness
The pull request is almost ready for merging. Addressing the typo in the error message is crucial. Additionally, it would be beneficial to confirm the naming consistency of the new tool call and ensure the dependency updates are thoroughly tested. I am unable to approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issue should be addressed before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
app/(chat)/api/chat/route.ts
(4 hunks)lib/ai/providers.ts
(1 hunks)package.json
(2 hunks)
🔇 Additional comments (7)
package.json (1)
23-23
: Package update to@ai-sdk/[email protected]
The update from 1.2.0 to 1.2.2 is necessary to support the new OpenAI Responses API features used elsewhere in the codebase. This change aligns with the PR objectives.
lib/ai/providers.ts (1)
28-29
: Updated model initialization to use Responses APIExcellent modification to switch from
openai()
toopenai.responses()
for both small and large models. This change leverages the new OpenAI Responses API which is the key feature being added in this PR.Note that the models
'title-model'
and'artifact-model'
(lines 34-35) still use the traditionalopenai()
function. This appears intentional as the PR seems focused on updating only the chat models.app/(chat)/api/chat/route.ts (5)
28-28
: Added import for OpenAI SDKGood addition - this import is necessary to support the new
webSearchPreview
tool implementation.
89-90
: Added Web Search Preview tool to active toolsWell implemented addition of the
webSearchPreview
tool to the list of experimental active tools. The tool is correctly conditionally applied only when not using the reasoning model.
105-109
: Disabled storage for OpenAI providerThis change configures the OpenAI provider to not store conversation data (
store: false
). This is a good practice for privacy and data management, aligning with the updates to use the Responses API.
147-147
: Fixed typo in error messageCorrected "occured" to "occurred" - good attention to detail.
101-104
:✅ Verification successful
Implemented Web Search Preview functionality
Good implementation of the
webSearchPreview
tool using the OpenAI tools API with a medium search context size. This aligns with the PR objective to demonstrate the OpenAI Web Search Preview functionality.
🌐 Web query:
What is the OpenAI Web Search Preview tool and how does it work?
💡 Result:
OpenAI Web Search Preview Tool: Overview and Functionality
What is the OpenAI Web Search Preview Tool?
The OpenAI Web Search Preview tool is a specialized capability integrated into OpenAI's latest generative AI models, notably versions like GPT-4o-search-preview and GPT-4o-mini-search-preview. This tool enables these models to perform real-time web searches as part of their response generation process, allowing them to provide answers with up-to-date, factually grounded information and cite online sources directly in their outputs[1][2][6].
How Does the Web Search Preview Work?
Model Integration: The tool is built into specific OpenAI models, which are fine-tuned to both interpret user queries and perform targeted web searches to supplement the model’s knowledge[1][6].
API Usage:
- Chat Completions API: When using models like
gpt-4o-search-preview
via the Chat Completions API, the model will automatically retrieve information from the web before responding to queries[6]. Developers can configure search options, such as the amount of external context to use, directly in API calls.- Responses API: Through the Responses API, the
web_search_preview
tool can be enabled within thetools
parameter. The model decides whether to invoke a web search based on the prompt, especially when questions require information beyond the model’s static knowledge base (knowledge cutoff)[4][5][6]. Developers can also manually guide or enforce tool usage via thetool_choice
parameter.Underlying Technology:
- The web search function is powered by a fine-tuned version of the GPT-4o model, trained using advanced synthetic data techniques and distillation from prior models. It leverages third-party search providers and direct content partnerships to source relevant, current web content[2][7].
- The model is capable of ingesting retrieved documents, extracting relevant passages, and synthesizing them into a coherent, cited response.
- Adjustments such as “search_context_size” (low, medium, high) allow developers to balance between comprehensiveness, response speed, and API cost[6][8].
Output Quality and Citations: Responses generated using the web search tool include inline citations linked to the original URLs, providing transparency and source traceability for the information presented[3][6].
Use Case Customization: The tool can be combined with other built-in tools (e.g., file search), and custom instructions can be layered to achieve complex workflows—such as combining user-specific data with external web information before presenting recommendations[5][7].
How Developers Use It
A typical API call using the web search tool involves specifying the model and enabling web search in the request. Here’s a Python snippet:
from openai import OpenAI client = OpenAI() response = client.chat.completions.create( model="gpt-4o-search-preview", web_search_options={ "search_context_size": "low", }, messages=[{ "role": "user", "content": "What movie won best picture in 2025?" }] ) print(response.choices[0].message.content)[6][4][8]
Who Can Access It?
The web search tool is available to API users (developers) and select ChatGPT users (such as Plus and Team subscribers) as of late 2024. It is gradually extending to more user tiers and modalities, including voice and canvas tools[2].
In summary, the OpenAI Web Search Preview tool integrates real-time search into AI responses, bridging the gap between static model knowledge and the dynamic, ever-changing information available on the internet. This empowers developers and end-users to receive current, accurately sourced answers within naturally flowing conversations[2][5][6].
Citations:
- 1: https://platform.openai.com/docs/models/gpt-4o-search-preview
- 2: https://openai.com/index/introducing-chatgpt-search/
- 3: https://www.youtube.com/watch?v=X0zYKuKdWxg
- 4: https://platform.openai.com/docs/guides/tools-web-search
- 5: https://platform.openai.com/docs/guides/tools
- 6: https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat&lang=python
- 7: https://www.youtube.com/watch?v=-fPZsngNMFs
- 8: https://www.youtube.com/watch?v=hswwoHNB4NQ
- 9: https://community.openai.com/t/is-the-search-web-model-available-through-the-api/1007058
- 10: https://learn.microsoft.com/en-us/answers/questions/2238261/will-azure-openai-support-openai-s-new-web-search
Verified Web Search Preview Implementation
The
webSearchPreview
tool is correctly set up with a mediumsearchContextSize
, ensuring the GPT-4o-search-preview model retrieves and synthesizes up-to-date web content. This meets the PR’s goal to demonstrate the OpenAI Web Search Preview functionality.
@@ -40,7 +40,7 @@ | |||
"@vercel/analytics": "^1.3.1", | |||
"@vercel/blob": "^0.24.1", | |||
"@vercel/postgres": "^0.10.0", | |||
"ai": "4.1.50", | |||
"ai": "4.1.54", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Package update to [email protected]
This update from 4.1.50 to 4.1.54 is required to support the OpenAI Responses API implementation. The PR comments indicate this adds 14 new transitive dependencies, which is expected for this feature addition.
🏁 Script executed:
#!/bin/bash
# Verify the compatibility of these packages by checking their latest versions
echo "Checking latest versions of @ai-sdk/openai and ai packages..."
npm view @ai-sdk/openai version
npm view ai version
Length of output: 202
Update ai
dependency to the latest published version (4.3.10)
npm registry shows that ai
@4.1.54 is two minor releases behind—the current latest is 4.3.10. To pick up bug fixes and improvements beyond the OpenAI Responses API support, please bump the version.
- File: package.json (line 43)
- Diff suggestion:
- "ai": "4.1.54",
+ "ai": "^4.3.10",
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"ai": "4.1.54", | |
"ai": "^4.3.10", |
Updates
ai
and@ai-sdk/openai
versions to support the new OpenAI Responses API.Updates the default "small" and "large" models to use the Responses API.
Adds a new
webSearchPreview
tool call to demo the new OpenAI Web Search Preview tool.Summary by CodeRabbit
New Features
Bug Fixes
Chores